/**
 * Test class for Parser.java
 * To compile this source code, you need to copy the files in com.matrix.math to ./directory.
 * 
 * @author Sultan
 * Last modified : April 28th, 2011
 */
public class ParserTests
{

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception
	{
		String matrices[] = {"1 2 3; 1 2 3", // should pass
							 "-1, 32, 44; 1 3 -43", // should fail
							 "[ 1.5  32.3  1e-15 ; 99 333.3 52", // should fail
							 "1$1$1$;3$3$2", // should fail
							 "1, 2, 3, 4;1, 2, 3, 4",// should pass
							 "1, 1, 1, 1, 1", // should pass
							 "34#32#1;1#22%33"}; // should fail
		
		
		String colvects[] = {"[1, 2, 3, 4, 5,]'", // should fail
							 "[1 2 3 4]'", // should pass
							 "[1 2 2.2, -2]'", // should fail
							 "[-99 -3 -2 12e-3]'", // should pass
							 "[1, 2, 3, 4, 5, 6 ]'",  // should pass
							 "[1.3, -3, -2.4]'"}; // should pass
		
		
		String vectors[] = {"<1i, 2j, 9k>", // should pass
							"<-1i -99j  -9.4k", // should fail
							"<-99 4j 3k>", // should fail
							"<2i 99w 33k>", // should fail
							"<2    i,  3 j  32223.3 k>", // should pass
							"<-2   i,  3 j  -32223.2 k>"}; // should pass
		
		// all constant should pass.
		String constants[] = {"-9.3",
							  "-1",
							  "11",
							  "0.02",
							  "12e-23"};
		
		
		
		Parser parser;
		System.out.println("Parser Class Test\n\n");
		System.out.println("1 - Test Parse Matrix Method");
		System.out.println("------------------------------------------------------------------------------------------");
		Matrix m;
		for(int i = 0; i < matrices.length; ++i)
		{
			System.out.print("Parser is reading\t"+matrices[i]+"\t\t\t");
			parser = new Parser(matrices[i]);
			try
			{
				parser.parse();
				m = parser.getMatrix();
				System.out.println("SUCESS\n");
				m.print();
			}
			catch(Exception e)
			{
				System.out.println("FAIL ");

				System.out.println(e.getMessage());
			}
			System.out.println();
			System.out.println("------------------------------------------------------------------------------------------\n");
		}
		
		
		
		System.out.println("******************************************************************************************\n");
		System.out.println("2 - Test Parse Column Vector Method");
		System.out.println("------------------------------------------------------------------------------------------");
		ColumnVector cv;
		for(int i = 0; i < colvects.length; ++i)
		{
			System.out.print("Parser is reading\t"+colvects[i]+"\t\t\t");
			parser = new Parser(colvects[i]);
			try
			{
				parser.parse();
				cv = parser.getColVect();
				System.out.println("SUCESS\n");
				cv.print();
			}
			catch(Exception e)
			{
				System.out.println("FAIL ");

				System.out.println(e.getMessage());
			}
			System.out.println();
			System.out.println("------------------------------------------------------------------------------------------\n");
		}

	
		
		System.out.println("******************************************************************************************\n");

		System.out.println("3 - Test parse Coordinate Vector Method");
		System.out.println("------------------------------------------------------------------------------------------");
		Vector vs;
		for(int i = 0; i < vectors.length; ++i)
		{
			System.out.print("Parser is reading\t"+vectors[i]+"\t\t\t");
			parser = new Parser(vectors[i]);
			try
			{
				parser.parse();
				vs = parser.getVector();
				System.out.println("SUCESS\n");
				System.out.println(vs.toString());
			}
			catch(Exception e)
			{
				System.out.println("FAIL ");

				System.out.println(e.getMessage());
			}
			System.out.println();
			System.out.println("------------------------------------------------------------------------------------------\n");
		}
		
		
		System.out.println("******************************************************************************************\n");

		System.out.println("4 - Test parse Constant Method");
		System.out.println("------------------------------------------------------------------------------------------");
		
		Constant cs;
		for(int i = 0; i < constants.length; ++i)
		{
			System.out.print("Parser is reading\t"+constants[i]+"\t\t\t");
			parser = new Parser(constants[i]);
			try
			{
				parser.parse();
				cs = parser.getConstant();
				System.out.println("SUCESS\n");
				System.out.println(cs.toString());
			}
			catch(Exception e)
			{
				System.out.println("FAIL ");

				System.out.println(e.getMessage());
			}
			System.out.println();
			System.out.println("------------------------------------------------------------------------------------------\n");
		}
	
	}// end main
}
